package com.anji.hyperneat.modular;

/**
 * Input mapper that provides support for a single float input value.
 * @author slusk
 *
 */
public class FloatInputMapper implements ICppnInputMapper {

	protected float val;
	protected float minVal;
	protected float maxVal;
	
	/**
	 * Constructor with value initialization.
	 * @param val
	 * @param minVal Minimum possible value that this mapper could ever hold.
	 * @param maxVal Maximum possible value that this mapper could ever hold.
	 */
	public FloatInputMapper(float val, int minVal, int maxVal) {
		this.val = val;
		this.minVal = minVal;
		this.maxVal = maxVal;
	}
	
	/** 
	 * Standard Constructor.
	 * @param minVal
	 * @param maxVal
	 */
	public FloatInputMapper(int minVal, int maxVal) {
		this.minVal = minVal;
		this.maxVal = maxVal;
	}
	
	
	@Override
	public float[] getInputs() {
		return new float[] {val};
	}

	@Override
	public int getNumInputs() {
		return 1;
	}
	
	/**
	 * Set the value for this mapper.
	 * @param val
	 */
	public void populateValue(float val) {
		this.val = val;
	}

	@Override
	public float[] getNormalizedInputs() {
		float norm = maxVal != minVal ? ((val - minVal) / (maxVal - minVal)) * 2 - 1 : 0.0f;
		return new float[] { norm };
	}
}
